package com.fzu.ess.sys.entity;

import com.fzu.ess.common.entity.BaseEntity;
import lombok.*;
import org.hibernate.annotations.*;
import org.hibernate.annotations.Cache;

import javax.persistence.*;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by ercha on 2015/10/16.
 */
@Entity
@Getter @Setter @NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
@DynamicInsert @DynamicUpdate
@Table(name = "sys_role")
public class Role extends BaseEntity {

    public Role(String id){
        this.id = id;
    }

    @Column(name = "name")
    private String name;

    @Column(name = "remark")
    private String remark;

    @ManyToMany(mappedBy = "roleList", fetch=FetchType.LAZY)
    @Fetch(FetchMode.SUBSELECT)
    @NotFound(action = NotFoundAction.IGNORE)
    @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
    private List<User> userList = new ArrayList<>();

    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(name = "sys_role_menu",
            joinColumns = { @JoinColumn(name = "role_id") },
            inverseJoinColumns = { @JoinColumn(name = "menu_id") })
    @Fetch(FetchMode.SUBSELECT)
    @NotFound(action = NotFoundAction.IGNORE)
    @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
    private List<Menu> menuList = new ArrayList<>();


//    public List<Menu> getMenuList() {
//        return menuList;
//    }
//
//    public void setMenuList(List<Menu> menuList) {
//        this.menuList = menuList;
//    }


}
